package com.zjhd.sealcutting.service.impl;

import com.google.common.collect.Maps;
import com.zjhd.sealcutting.dao.OperationLogMapper;
import com.zjhd.sealcutting.domain.ExpressInfo;
import com.zjhd.sealcutting.domain.OperationLog;
import com.zjhd.sealcutting.domain.UserInfo;
import com.zjhd.sealcutting.param.OperationLogSearchQuery;
import com.zjhd.sealcutting.service.OperationLogService;
import com.zjhd.sealcutting.vo.SearchResult;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * TODO  操作日志管理
 *
 * @author wangchao
 * @version 1.0
 * @date 2020/12/11 11:37
 */
@Service
public class OperationLogServiceImpl implements OperationLogService {

    @Autowired
    private OperationLogMapper operationLogMapper;

    /**
     * TODO   分页查询操作日志
     * @author wangchao
     * @date 2020/12/11 11:43
     * @param
     * @return
     */
    @Override
    public SearchResult queryOperationLogParamlist(OperationLogSearchQuery param) throws Exception {
        //定义map 封装查询参数到map中
        Map<String, Object> map = Maps.newLinkedHashMap();
        if(StringUtils.isNotBlank(param.getSearchName())){
            map.put("searchName",param.getSearchName());
        }
        if(StringUtils.isNotBlank(param.getStartTime())){
            map.put("startTime",param.getStartTime());
        }
        if(StringUtils.isNotBlank(param.getEndTime())){
            map.put("endTime",param.getEndTime());
        }
        //当前页  分页数
        map.put("pageIndex", (Integer.parseInt(param.getPageIndex()) - 1) * Integer.parseInt(param.getPageSize()));
        map.put("pageSize", Integer.parseInt(param.getPageSize()));
        List<OperationLog> operationLogs=operationLogMapper.getPageList(map);
        long totalCount=operationLogMapper.getTotal(map);
        if(operationLogs.size()>0){
            return new SearchResult.Builder<List<OperationLog>>()
                    .setCurrent(Integer.parseInt(param.getPageIndex()))
                    .setPageSize(Integer.parseInt(param.getPageSize()))
                    .setTotalCount(totalCount)
                    .setPagedItems(operationLogs == null ? new ArrayList() : operationLogs)
                    .build();
        }else {
            return new SearchResult.Builder().setPagedItems(new ArrayList()).build();
        }
    }
}
